home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / GENetReleaseƒ / Extras / Motion.c < prev    next >
Text File  |  1993-12-06  |  2KB  |  77 lines

  1. /*
  2.     Motion.c
  3.     
  4.     Motion routines for Graphic Elements
  5.     
  6.     Copyright 1993 by Al Evans. All rights reserved.
  7.     
  8.     11/3/93
  9. */
  10.  
  11.  
  12. #include "Motion.h"
  13.  
  14. void InitMotion(MParamPtr motionRec, short percentFriction, short percentElasticity)
  15. {
  16.     motionRec->currMotion.v = motionRec->currMotion.h = 0;
  17.     motionRec->friction = (((long) percentFriction) << 16) / 100;
  18.     motionRec->frictAcc = 0;
  19.     motionRec->elasticity = (((long) percentElasticity) << 16) / 100;
  20. }
  21.  
  22. GEDirection CheckLimits(Rect *objRect, Rect *limitRect)
  23. {
  24.     if (objRect->right >= limitRect->right)
  25.         return right;
  26.     if (objRect->left <= limitRect->left)
  27.         return left;
  28.     if (objRect->top <= limitRect->top)
  29.         return up;
  30.     if (objRect->bottom >= limitRect->bottom)
  31.         return down;
  32.     return none;
  33. }
  34.  
  35. void DoFriction(MParamPtr motion)
  36. {
  37.     short temp;
  38.     if (motion->currMotion.h) {
  39.         temp = motion->currMotion.h;
  40.         if (temp < 0)
  41.             temp = -temp;
  42.         motion->frictAcc += temp * motion->friction;
  43.         temp = (motion->frictAcc >> 16);                        //integer part
  44.         motion->frictAcc -= (motion->frictAcc & 0xFFFF0000);    //keep fractional part
  45.         if (motion->currMotion.h > 0)
  46.             motion->currMotion.h -= temp;
  47.         else
  48.             motion->currMotion.h += temp;
  49.     }
  50. }
  51.  
  52.  
  53. void DoBounce(VHSelect direction, MParamPtr motion)
  54. {
  55.     long temp, compare;
  56.     
  57.     if (direction == v)
  58.         temp = motion->currMotion.v;
  59.     else
  60.         temp = motion->currMotion.h;
  61.     temp = -temp;
  62.     compare = temp;
  63.     temp = (temp * motion->elasticity) >> 16;
  64.     if (compare == temp) {
  65.         if (temp > 0)
  66.             temp -= 1;
  67.         else
  68.             temp += 1;
  69.     }
  70.     if (direction == v)
  71.         motion->currMotion.v = temp;
  72.     else
  73.         motion->currMotion.h = temp;
  74. }
  75.  
  76.  
  77.